package com.ddzj.scaffold.controller;

import com.ddzj.scaffold.handle.MyLocalThread;
import com.ddzj.scaffold.vo.AjaxResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.http.HttpRequest;

/**
 * @Author:yangzibo
 * @CreateTime:2024-04-14 14:11
 * @Description:
 * @Version:1.0
 **/
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private RedisTemplate redisTemplate;

    //hasAuthority('bj') and hasAuthority('bjh') 且
    //hasAnyAuthority('bj','bjh') 或
    @RequestMapping("/testLogin")
    @PreAuthorize("hasAnyAuthority('bj') and hasAuthority('bjj')")
    public AjaxResultVo testLogin(){
        return AjaxResultVo.ok();
    }

    @RequestMapping("/testRedis")
    public AjaxResultVo testRedis(){
        redisTemplate.opsForValue().set("t1","张三");
        return AjaxResultVo.ok(redisTemplate.opsForValue().get("t1"));
    }

    @RequestMapping("/testLocalTread")
    public AjaxResultVo testLocalTread(){
        MyLocalThread.setVal("1", "2");
        MyLocalThread.showMap();
        try {
            Thread.sleep(300000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        MyLocalThread.clear();
        return AjaxResultVo.ok("ok");
    }

    @RequestMapping("/tocalTread")
    public AjaxResultVo tocalTread(){
        MyLocalThread.showMap();
        try {
            Thread.sleep(30000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return AjaxResultVo.ok("ok");
    }
}
